package com.ruoyi.web.controller.eval;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dgy.eval.domain.TeachEvalItem;
import com.dgy.eval.service.ITeachEvalItemService;
import com.dgy.eval.service.ITeachEvalSummaryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.dgy.eval.domain.TeachEvalRecord;
import com.dgy.eval.service.ITeachEvalRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教学评价记录Web端Controller
 * 
 * @author ccc
 * @date 2025-02-12
 */
@RestController
@RequestMapping("/eval/record")
public class TeachEvalRecordController extends BaseController
{
    @Autowired
    private ITeachEvalRecordService teachEvalRecordService;

    @Autowired
    private ITeachEvalItemService teachEvalItemService;

    @Autowired
    private ITeachEvalSummaryService teachEvalSummaryService;

    /**
     * 查询教学评价记录列表
     */
    @PreAuthorize("@ss.hasPermi('eval:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachEvalRecord teachEvalRecord)
    {
        startPage();
        List<TeachEvalRecord> list = teachEvalRecordService.selectTeachEvalRecordList(teachEvalRecord);
        return getDataTable(list);
    }

    /**
     * 导出教学评价记录列表
     */
    @PreAuthorize("@ss.hasPermi('eval:record:export')")
    @Log(title = "教学评价记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachEvalRecord teachEvalRecord)
    {
        List<TeachEvalRecord> list = teachEvalRecordService.selectTeachEvalRecordList(teachEvalRecord);
        ExcelUtil<TeachEvalRecord> util = new ExcelUtil<TeachEvalRecord>(TeachEvalRecord.class);
        util.exportExcel(response, list, "教学评价记录数据");
    }

    /**
     * 删除教学评价记录
     */
    @PreAuthorize("@ss.hasPermi('eval:record:remove')")
    @Log(title = "教学评价记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        // 删除评价记录
        teachEvalRecordService.deleteTeachEvalRecordByRecordIds(recordIds);
        // 删除对应的问题
        teachEvalItemService.deleteTeachEvalItemByRecordIds(recordIds);
        // 删除对应的教学评价总结
        teachEvalSummaryService.deleteTeachEvalSummaryByRecordIds(recordIds);
        return toAjax(true);
    }

    /**
     * 获取教学评价记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('eval:record:detail')")
    @GetMapping(value = "/detail/{recordId}")
    public AjaxResult detail(@PathVariable("recordId") Long recordId)
    {
        return success(teachEvalRecordService.selectTeachEvalRecordByRecordId(recordId));
    }

    /**
     * 获取教学评价记录所填的问题列表
     */
    @PreAuthorize("@ss.hasPermi('eval:record:getItemList')")
    @GetMapping(value = "/getItemList/{recordId}")
    public AjaxResult getItemList(@PathVariable("recordId") Long recordId)
    {
        TeachEvalItem teachEvalItem = new TeachEvalItem();
        teachEvalItem.setRecordId(recordId);
        return success(teachEvalItemService.selectTeachEvalItemList(teachEvalItem));
    }

    /**
     * 获取教学评价总结信息
     */
    @PreAuthorize("@ss.hasPermi('eval:record:getSummary')")
    @GetMapping(value = "/getSummary/{recordId}")
    public AjaxResult getSummary(@PathVariable("recordId") Long recordId)
    {
        return success(teachEvalSummaryService.selectTeachEvalSummaryByRecordId(recordId));
    }
}
